package cn.gok.snacks;

import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

public class TestMain {
    public static void main(String[] args) throws InstantiationException, IllegalAccessException, NoSuchMethodException, InvocationTargetException {
        Class<User> aClass = User.class;
        Field[] fields = aClass.getDeclaredFields();
        User user = aClass.newInstance();
        for (Field field : fields) {
            NotNull aNull = field.getAnnotation(NotNull.class);
            if(aNull!=null){
                String fieldGetMethod = "getName";
                Method method = aClass.getDeclaredMethod(fieldGetMethod);
                Object invoke = method.invoke(user);
                if (invoke  == null){
                    System.out.println(aNull.name()+aNull.value());
                }else {
                    System.out.println(aNull.name()+"不为空");
                }
            }
        }
    }
}
